<template>
    <view class="content">
        <u-cell-group>
            <u-cell :value="item.deal_text" v-for="item in orderList" :key="item.id">
                <view slot="title" class="u-slot-title">
                    <view style="">
                        {{ item.code }}
                    </view>
                </view>
                <view slot="label" class="u-slot-label">
                    <view style="color:#909193">
                        客户：{{ item.business.nickname ? item.business.nickname : '未知' }}
                    </view>
					<view style="color:#909193">
					    订单总额：{{ item.total ? item.total : '未知' }}
					</view>
                    <view class="btn">
                        <u-button type="primary" :customStyle="btnStyle" size="mini" text="详情"
                            @click="getToinfo(item.id)"></u-button>
                        <u-button type="error" :customStyle="btnStyle" size="mini" text="删除"
                            @click="getDel(item, 'error')"></u-button>
                    </view>
                </view>
            </u-cell>
        </u-cell-group>
        <u-modal :show="show" :content='content' :showCancelButton="true" @confirm="confirm"
            @cancel="show = false"></u-modal>
        <u-toast ref="uToast"></u-toast>
    </view>
</template>

<script>
export default {
    onLoad()
    {
        this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}

        this.$u.auth.check()

        this.getorderData()
    },
    data() {
        return {
            btnStyle: {
                width: '10%',
                display: "inline-block",
                marginRight: '5px',
                marginTop: '10px',
                lineHeight: '20px'
            },
            orderList: [],
            LoginUser: {},
            show: false,
            content: '确认是否删除该订单?',
            // 客户id
            id: 0,
            // error: 表示是调用删除确认框， warning：表示是调用申请确认框
            status: 'error'
        }
    },
    methods: {
        async getorderData()
        {
			let data={
				Adminid:this.LoginUser.id
			}
			console.log(data)
            let result = await this.$u.api.order.getSuborder(data)

            if(result.code === 1)
            {
                this.orderList = result.data
            }
        },
        getDel(value,status)
        {
            this.content = '确认是否删除' + value.code + '订单？'
            this.status = status
            this.show = true
            this.id = value.id
        },
        getToinfo(id)
        {
            this.$u.route({
                url:'/packageC/suborder/info',
                params:{
                    orderid:id
                }
            })
        },
		async confirm(){
			this.show = false;
			let _this=this;
			let data={
				orderid:this.id,
				Adminid:this.LoginUser.id
			}
			let result = await this.$u.api.order.delSuborder(data)
			if(result.code === 1)
			{
			    this.$refs.uToast.show({
			        type:'success',
			        message:result.msg,
					complete(){
						_this.getorderData()
					}	
			    })
			    return false
			}else{
			    this.$refs.uToast.show({
			        type:'error',
			        message:result.msg
			    })
			    return false
			}
			
		}
    }
}
</script>